package com.chencs.aso.cheat.service;

import com.chencs.aso.cheat.mapper.CheatMapper;
import com.chencs.vo.biz.cheat.AccountModel;
import com.chencs.vo.biz.cheat.DeviceLogModel;
import com.chencs.vo.biz.cheat.DeviceModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by fangzehua on 2017/8/28.
 */
@Service
@Transactional
public class CheatService {

    @Autowired
    private CheatMapper cheatMapper;

    public void devRegister(DeviceModel deviceModel){

        DeviceModel model  = cheatMapper.findDeviceByUid(deviceModel.getUid());
        if (model!=null){
            upDevice(deviceModel.getUid());
        }else{
            cheatMapper.devRegister(deviceModel);
        }
    }



    public  void  addDevLog(DeviceLogModel model){

        cheatMapper.addDevLog(model);
    }

    public  DeviceModel findDeviceByUid(String uid){
       // DeviceModel deviceModel  = cheatMapper.findDeviceByUid(uid);
      return   cheatMapper.findDeviceByUid(uid);
    }

    public  void upDevice(String uid){
        cheatMapper.upDevice(uid);
    }

    public AccountModel getAccountMode(){

        AccountModel accountModel = cheatMapper.findAccountMode();
        if(accountModel!=null){
            System.out.println("修改状态");
            cheatMapper.upAccount(accountModel.getId());
        }
        return  accountModel;
    }


}
